package com.shxy.rlzy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.shxy.rlzy.entity.Role;
import com.shxy.rlzy.entity.RoleMenu;
import com.shxy.rlzy.mapper.RoleMapper;
import com.shxy.rlzy.mapper.RoleMenuMapper;
import com.shxy.rlzy.mapper.UserMapper;
import com.shxy.rlzy.service.IRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author tanhao
 * @since 2021-08-16
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IRoleService {

    private RoleMapper roleMapper;
    private UserMapper userMapper;
    @Autowired
    public void setRoleMapper(RoleMapper roleMapper) {
        this.roleMapper = roleMapper;
    }

    @Autowired
    public void setUserMapper(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Override
    public Role getByName(String name) {
        QueryWrapper<Role> qw = new QueryWrapper<>();
        qw.eq("name", name);
        return getOne(qw);
    }

    @Override
    public Role getByCode(String code) {
        QueryWrapper<Role> qw = new QueryWrapper<>();
        qw.eq("code", code);
        return getOne(qw);
    }

    @Override
    public Role getByUsername(String username) {
        return roleMapper.getByUsername(username);
    }

    @Override
    public Role getByUserId(long userId) {
        return roleMapper.getByUserId(userId);
    }

    @Override
    public Role getById(long roleId) {
        return roleMapper.getById(roleId);
    }
}
